package com.rm.zeyou.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.vo.response.SelectSalesmanChannelListResponseVo;
import com.rm.zeyou.vo.response.SelectSalesmanChannelOrderDetailResponseVo;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:09
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Delete(" delete  from t_user where id = #{id}")
    void deleteUser(@Param("id") Long id);

    @Update("update t_user set user_balance = user_balance - #{amount} where id = #{userId} and user_balance >= #{amount}")
    Integer subBalance(@Param("userId") Long userId, @Param("amount") BigDecimal amount);

    @Update("update t_user set user_balance = user_balance + #{amount} where id = #{userId}")
    Integer addBalance(@Param("userId") Long userId, @Param("amount") BigDecimal amount);


    List<SelectSalesmanChannelOrderDetailResponseVo> selectChannelList(@Param("invitationCode") String invitationCode,@Param("keyWord") String keyWord);

    List<SelectSalesmanChannelListResponseVo> selectSalesmanChannelList(@Param("invitationCode") String invitationCode,@Param("keyWord") String keyWord);

    @Select("select * from t_user where user_tel = #{tel}")
    User selectUser(@Param("tel") String tel);

    @Select("select * from t_user where unionid = #{unionid}")
    User selectUserByOpenId(@Param("unionid") String unionid);

    @Update("update t_user set is_first_login = 0 where id = #{id}")
    Integer updateFirstLogin(@Param("id") Long id);
}
